package com.lineage.server.datatables.lock;

import com.lineage.server.datatables.sql.ClanEmblemTable;
import com.lineage.server.datatables.storage.ClanEmblemStorage;
import com.lineage.server.templates.L1EmblemIcon;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ClanEmblemReading {
  private final Lock _lock = new ReentrantLock(true);
  
  private final ClanEmblemStorage _storage = (ClanEmblemStorage)new ClanEmblemTable();
  
  private static ClanEmblemReading _instance;
  
  public static ClanEmblemReading get() {
    if (_instance == null)
      _instance = new ClanEmblemReading(); 
    return _instance;
  }
  
  public void load() {
    this._lock.lock();
    try {
      this._storage.load();
    } finally {
      this._lock.unlock();
    } 
  }
  
  public L1EmblemIcon get(int clan_id) {
    L1EmblemIcon tmp;
    this._lock.lock();
    try {
      tmp = this._storage.get(clan_id);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public L1EmblemIcon getEmblem(int emblemid) {
    L1EmblemIcon tmp;
    this._lock.lock();
    try {
      tmp = this._storage.getEmblem(emblemid);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  


  
  public void addDeclanEmblem(int clan_id, L1EmblemIcon emblemIcon) {
    this._lock.lock();
    try {
      this._storage.addDeclanEmblem(clan_id, emblemIcon);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void deleteIcon(int clan_id) {
    this._lock.lock();
    try {
      this._storage.deleteIcon(clan_id);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public L1EmblemIcon storeClanIcon(int clan_id, byte[] emblemicon, int emblemid) {
    L1EmblemIcon tmp;
    this._lock.lock();
    try {
      tmp = this._storage.storeClanIcon(clan_id, emblemicon, emblemid);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
	/**
	 * 新建 ICON
	 */
	public L1EmblemIcon storeClanIcon(final int clan_id, final byte[] emblemicon) {
		this._lock.lock();
		L1EmblemIcon tmp;
		try {
			tmp = this._storage.storeClanIcon(clan_id, emblemicon);

		} finally {
			this._lock.unlock();
		}
		return tmp;
	}
  
  public void updateClanIcon(L1EmblemIcon emblemIcon) {
    this._lock.lock();
    try {
      this._storage.updateClanIcon(emblemIcon);
    } finally {
      this._lock.unlock();
    } 
  }
}
